package io.jt808.proto.req;

import io.norland.annotations.Proto;
import io.norland.buffer.AutoBuffer;
import io.norland.proto.IProto;
import lombok.Data;

/**
 * 终端注册
 */
@Proto("0100")
@Data
public class JT0100 implements IProto {
    /**
     * 省域ID
     */
    private short provinceId;
    /**
     * 市、县域ID
     */
    private short cityId;
    /**
     * 制造商ID
     */
    private String manufactureId;
    /**
     * 终端型号
     */
    private String terminalModelNo;
    /**
     * 终端ID
     */
    private String terminalId;
    /**
     * 车牌颜色
     */
    private byte plateColor;
    /**
     * 车牌号码
     */
    private String plateNo;

    public final byte[] writeToBytes() {
        AutoBuffer buff = new AutoBuffer();
        buff.writeShort(provinceId);
        buff.writeShort(cityId);
        buff.writeString(manufactureId, 5);
        buff.writeString(terminalModelNo, 20);
        buff.writeString(terminalId, 7);
        buff.writeByte(plateColor);
        buff.writeString(plateNo);
        return buff.array();
    }

    public final void readFromBuf(AutoBuffer buff) {
        provinceId = buff.readShort();
        cityId = buff.readShort();
        manufactureId = buff.readString(5);
        terminalModelNo = buff.readString(20);
        terminalId = buff.readString(7);
        plateColor = buff.readByte();
        plateNo = buff.readString();
    }
//    public static void main(String[] args){
//        String hexString="7e0100002d01680002423000010044012f373031313142534a2d4f3900000000000000000000000000003030303030303001d4c1423838383838367e";
//        byte[] bytes= Tools.HexString2Bytes(hexString);
//        AutoBuffer buffer=new AutoBuffer(bytes);
//        JT0100 jt0100=new JT0100();
//        jt0100.readFromBuf(buffer);
//        System.out.printf(new String(jt0100.writeToBytes()).equals(hexString)+"");
//    }
}